//-----------------------------------------------------------------------
// <copyright file="MemberAllocation.cs" company="Expectra Technology">
//     Copyright (c) Expectra Technology. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace DeltaFlex.Negoci
{
    /// <summary>
    /// Abstract class for actions when no bussines member allocation is possible
    /// </summary>
    internal abstract class NoAllocationAbstract
    {
        public abstract void doAction(string columnName);
    }

    /// <summary>
    /// Class for error when no allocation is possible due to DBNull.Value and the member type can not be null
    /// </summary>
    internal class NoAllocationError : NoAllocationAbstract
    {
        /// <summary>
        /// Creates a new NoAllocationError instance
        /// </summary>
        public NoAllocationError()
        {
        }

        public override void doAction(string columnName)
        {
            throw new System.Data.DataException(
                String.Format(
                        "The column {0} retrieved from data storage can not be null",
                        columnName));
        }
    }

    /// <summary>
    /// Class for ignore when no allocation is possible due to DBNull.Value and the member type can not be null
    /// </summary>
    internal class NoAllocationIgnore : NoAllocationAbstract
    {
        /// <summary>
        /// Creates a new NoAllocationIgnore instance
        /// </summary>
        public NoAllocationIgnore()
        {
        }

        public override void doAction(string columnName)
        {
            // Ignore
        }
    }

    /// <summary>
    /// Static Class for bussines field allocation.
    /// Provides an overloading frame for bussines field allocation. 
    /// When bussines field type changes, the overload field allocation changes acordingly
    /// </summary>
    public static class MemberAllocation
    {
        
        /// <summary>
        /// No allocation responses
        /// </summary>
        private static NoAllocationAbstract _noAllocAction = initNoAllocationResponse();
        
        private static NoAllocationAbstract initNoAllocationResponse()
        {
            bool noAllocationConf = (null != ConfigurationManager.AppSettings.Get("DeltaFlex.Negoci.MemberAllocation.NoAllocAction"));
            if (noAllocationConf)
            {
                Type noAllocType = Type.GetType(ConfigurationManager.AppSettings.Get("DeltaFlex.Negoci.MemberAllocation.NoAllocAction"));
                if (null != noAllocType)
                {
                    return noAllocType.GetConstructor(new Type[] { }).Invoke(new object[] { }) as NoAllocationAbstract;
                }
                else
                {
                  return new NoAllocationIgnore() as NoAllocationAbstract;
                }
            }
            else
            {
                return new NoAllocationIgnore() as NoAllocationAbstract;
            }
        }

        /// <summary>
        /// Allocate a private member with string type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref string member)
        {
            object resultValue;
            try
            {
                resultValue = record[columnName];
                if (!DBNull.Value.Equals(resultValue))
                {
                    member = Convert.ToString(resultValue);
                }
                else
                {
                    member = null;
                }
            }
            catch
            {
                return;
            }
        }

        /// <summary>
        /// Allocate a private member with byte[] type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref byte[] member)
        {
            object resultValue;
            try
            {
                resultValue = record[columnName];
                if (!DBNull.Value.Equals(resultValue))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    MemoryStream ms = new MemoryStream();
                    bf.Serialize(ms, resultValue);
                    member = ms.ToArray();
                }
                else
                {
                    member = null;
                }
            }
            catch
            {
                return;
            }
        }

        /// <summary>
        /// Allocate a private member with bool type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref bool member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToBoolean(resultValue);
            }
            else
            {
                _noAllocAction.doAction(columnName);
            }
        }

        /// <summary>
        /// Allocate a private member with bool? type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref bool? member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToBoolean(resultValue);
            }
            else
            {
                member = null;
            }
        }

        /// <summary>
        /// Allocate a private member with ushort type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref ushort member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToUInt16(resultValue);
            }
            else
            {
                _noAllocAction.doAction(columnName);
            }
        }

        /// <summary>
        /// Allocate a private member with ushort? type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref ushort? member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToUInt16(resultValue);
            }
            else
            {
                member = null;
            }
        }

        /// <summary>
        /// Allocate a private member with short type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref short member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToInt16(resultValue);
            }
            else
            {
                _noAllocAction.doAction(columnName);
            }
        }

        /// <summary>
        /// Allocate a private member with short? type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref short? member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToInt16(resultValue);
            }
            else
            {
                member = null;
            }
        }

        /// <summary>
        /// Allocate a private member with uint type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref uint member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToUInt32(resultValue);
            }
            else
            {
                _noAllocAction.doAction(columnName);
            }
        }

        /// <summary>
        /// Allocate a private member with uint? type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref uint? member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToUInt32(resultValue);
            }
            else
            {
                member = null;
            }
        }

        /// <summary>
        /// Allocate a private member with int type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref int member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToInt32(resultValue);
            }
            else
            {
                _noAllocAction.doAction(columnName);
            }
        }

        /// <summary>
        /// Allocate a private member with int? type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref int? member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToInt32(resultValue);
            }
            else
            {
                member = null;
            }
        }

        /// <summary>
        /// Allocate a private member with ulong type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref ulong member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToUInt64(resultValue);
            }
            else
            {
                _noAllocAction.doAction(columnName);
            }
        }

        /// <summary>
        /// Allocate a private member with ulong? type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref ulong? member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToUInt64(resultValue);
            }
            else
            {
                member = null;
            }
        }

        /// <summary>
        /// Allocate a private member with long type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref long member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToInt64(resultValue);
            }
            else
            {
                _noAllocAction.doAction(columnName);
            }
        }

        /// <summary>
        /// Allocate a private member with long? type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref long? member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToInt64(resultValue);
            }
            else
            {
                member = null;
            }
        }

        /// <summary>
        /// Allocate a private member with float type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref float member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = float.Parse(resultValue.ToString());
            }
            else
            {
                _noAllocAction.doAction(columnName);
            }
        }

        /// <summary>
        /// Allocate a private member with float? type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref float? member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = float.Parse(resultValue.ToString());
            }
            else
            {
                member = null;
            }
        }

        /// <summary>
        /// Allocate a private member with double type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref double member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToDouble(resultValue);
            }
            else
            {
                _noAllocAction.doAction(columnName);
            }
        }

        /// <summary>
        /// Allocate a private member with double? type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref double? member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToDouble(resultValue);
            }
            else
            {
                member = null;
            }
        }

        /// <summary>
        /// Allocate a private member with decimal type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref decimal member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToDecimal(resultValue);
            }
            else
            {
                _noAllocAction.doAction(columnName);
            }
        }

        /// <summary>
        /// Allocate a private member with decimal? type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref decimal? member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToDecimal(resultValue);
            }
            else
            {
                member = null;
            }
        }

        /// <summary>
        /// Allocate a private member with DateTime type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref DateTime member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToDateTime(resultValue);
            }
            else
            {
                _noAllocAction.doAction(columnName);
            }
        }

        /// <summary>
        /// Allocate a private member with DateTime? type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        public static void Allocate(IDataRecord record, string columnName, ref DateTime? member)
        {
            // Validate the params when debug
#if DEBUG
            if (null == record)
            {
                throw new ArgumentException("The record suplied can not be null");
            }

            if (null == columnName)
            {
                throw new ArgumentException("The columnName name suplied can not be null");
            }
            else if (string.Empty.Equals(columnName))
            {
                throw new ArgumentException("The column name suplied can not be empty");
            }
#endif
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                member = Convert.ToDateTime(resultValue);
            }
            else
            {
                member = null;
            }
        }

        /// <summary>
        /// Allocate a private member with DateTime? type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        /// <param name="enumType">The Enum Type to assign</param>
        /// <param name="canBeNull">Can be null the Enum member?</param>
        public static void Allocate(IDataRecord record, string columnName, Type enumType, ref Enum member, bool canBeNull)
        {
            object resultValue;
            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
               member = Enum.Parse(enumType, Convert.ToString(resultValue)) as Enum;
            }
            else
            {
                if (canBeNull)
                {
                    member = null as Enum;
                }
                else
                {
                    _noAllocAction.doAction(columnName);
                }
            }
        }

        /// <summary>
        /// Allocate a private member with DateTime? type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' and allocated in the 
        /// bussines member 'member'
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        /// <param name="member">The bussines member the value readed will be allocated in</param>
        /// <param name="enumType">The Enum Type to assign</param>
        /// <param name="canBeNull">Can be null the Enum member?</param>
        public static Enum GetEnum(IDataRecord record, string columnName, Type enumType, bool canBeNull)
        {
            object resultValue;

            try
            {
                resultValue = record[columnName];
            }
            catch
            {
                return null;
            }

            if (!DBNull.Value.Equals(resultValue))
            {
                return Enum.Parse(enumType, Convert.ToString(resultValue)) as Enum;
            }
            else
            {
                if (canBeNull)
                {
                    return null;
                }
                else
                {
                    _noAllocAction.doAction(columnName);
                    return null;
                }
            }
        }

        /// <summary>
        /// Gets a column fied with string type
        /// The value is retrieved from the column 'columName' of the IDataRecord 'record' 
        /// </summary>
        /// <param name="record">The IDataRecord to read from</param>
        /// <param name="columnName">The column to read from the IDataRecord</param>
        public static string GetString(IDataRecord record, string columnName)
        {
            object resultValue;
            try
            {
                resultValue = record[columnName];
                if (!DBNull.Value.Equals(resultValue))
                {
                    return Convert.ToString(resultValue);
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }
    }
}